package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.dao.CourseDao;
import com.qf.dao.TypeDao;
import com.qf.entity.TbCourse;
import com.qf.entity.TbType;
import com.qf.service.CourseService;
import com.qf.service.TypeService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 王希卓
 * @Date 2023/7/18 14:26
 * 课程分类业务实现
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeDao, TbType> implements TypeService {
    @Autowired(required = false)
    TypeDao typeDao;
    @Autowired(required = false)
    CourseService courseService;
    /**
     * 查询所有分类
     * @return
     */
    @Override
    public ResultMsg findAll() {
        List<TbType> list = this.list();
        return ResultMsg.success(list);
    }

    @Override
    public ResultMsg findCoursesByTypeName(int page,int limit,String keyword,String typeName) {
        TbType tbType = typeDao.selectTypeByName(typeName);
        if (tbType == null){
           return courseService.findAll(page,limit,keyword);
        }
        return courseService.findByType(page, limit, tbType.getTypeId(), keyword);
    }
}
